package com.xhs.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.If;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.xhs.dto.request.EnterprisePageParams;
import com.xhs.entity.MeEnterpriseEntity;
import com.xhs.mapper.MeEnterpriseMapper;
import com.xhs.message.Result;
import com.xhs.message.ReturnResult;
import com.xhs.service.MeEnterpriseService;
import org.springframework.stereotype.Service;

import static com.xhs.entity.table.MeEnterpriseEntityTableDef.ME_ENTERPRISE_ENTITY;

/**
 * 企业信息表 服务层实现。
 *
 * @author xhs
 * @since 2024-07-18
 */
@Service
public class MeEnterpriseServiceImpl extends ServiceImpl<MeEnterpriseMapper, MeEnterpriseEntity> implements MeEnterpriseService {

    /**
     * 分页查询企业信息
     *
     * @param pageParams 查询条件
     * @return ReturnResult<Page < MeEnterpriseEntity>>
     */
    @Override
    public ReturnResult<Page<MeEnterpriseEntity>> page(EnterprisePageParams pageParams) {
        Page<MeEnterpriseEntity> page = new Page<>(pageParams.getPageNumber(), pageParams.getPageSize());
        Page<MeEnterpriseEntity> entityPage = queryChain()
                .select(ME_ENTERPRISE_ENTITY.DEFAULT_COLUMNS)
                .from(ME_ENTERPRISE_ENTITY)
                .where(ME_ENTERPRISE_ENTITY.CORPORATE_NAME.like(pageParams.getCorporateName(), If::hasText))
                .page(page);
        return ReturnResult.build(Result.QUERY_SUCCESS, entityPage);
    }
}
